package org.jeecg.modules.flow.record.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.flow.record.entity.WmsFlowRecord;
import org.jeecg.modules.flow.record.mapper.WmsFlowRecordMapper;
import org.jeecg.modules.flow.record.service.IWmsFlowRecordService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 业务流程记录信息
 * @Author: jeecg-boot
 * @Date:   2023-09-21
 * @Version: V1.0
 */
@Service
public class WmsFlowRecordServiceImpl extends ServiceImpl<WmsFlowRecordMapper, WmsFlowRecord> implements IWmsFlowRecordService {
	
	@Autowired
	private WmsFlowRecordMapper wmsFlowRecordMapper;
	
	@Override
	public List<WmsFlowRecord> selectByMainId(String mainId) {
		return wmsFlowRecordMapper.selectByMainId(mainId);
	}

	@Override
	public boolean isCompleted(String infoId) {
		//总节点数(除去草稿节点)
		List<WmsFlowRecord> flowRecords = wmsFlowRecordMapper.selectList(new LambdaQueryWrapper<WmsFlowRecord>()
				.eq(WmsFlowRecord::getInfoId, infoId)
				.notIn(WmsFlowRecord::getFlowCode, Arrays.asList("start","end"))
				.ne(WmsFlowRecord::getDraft,0)
		);
		if((flowRecords.size()-1)==0){
			//除去开始结束节点、当前节点、草稿节点如果数量为0,说明当前节点是最后一个
			return true;
		}else {
			return false;
		}

	}
}
